Skip to content

refactor: app 실행 전 ELK+Filebeat 실행#193

Merged
lsh2613 merged 1 commit intodevfrom
refactor/#192
Jul 11, 2025
Merged

refactor: app 실행 전 ELK+Filebeat 실행#193
lsh2613 merged 1 commit intodevfrom
refactor/#192

Conversation

@lsh2613
Copy link
Contributor

@lsh2613 lsh2613 commented Jul 11, 2025

⭐ Summary

#192


📌 Tasks

  1. 배포 환경에서 app 실행 전 ELK+Filebeat 실행

## ETC - codedeploy appspec에서 hooks 옵션을 통해 순서를 조정해줄 수 있어서 이를 활용했습니다. - ELK+Filebeat 중 하나 이상의 컨테이너가 다운된 경우에만 재실행되도록 설정해놨습니다

@lsh2613 lsh2613 self-assigned this Jul 11, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jul 11, 2025

📝 Walkthrough

Walkthrough

appspec.yml 파일에 BeforeInstall 훅이 추가되어, 배포 전 scripts/pre_install.sh 스크립트가 실행되도록 설정되었습니다. 새로 추가된 pre_install.sh는 ELK 스택 및 Filebeat 관련 도커 컨테이너의 상태를 점검하고, 필요 시 컨테이너를 재시작하는 로직을 포함합니다.

Changes

파일/경로 변경 요약
appspec.yml BeforeInstall 훅 추가: 배포 전 scripts/pre_install.sh 실행 설정
scripts/pre_install.sh ELK 및 Filebeat 도커 컨테이너 상태 점검 및 필요 시 재시작 스크립트 추가

Sequence Diagram(s)

sequenceDiagram
    participant CodeDeploy
    participant EC2
    participant pre_install.sh
    participant Docker

    CodeDeploy->>EC2: BeforeInstall 훅 트리거
    EC2->>pre_install.sh: 스크립트 실행
    pre_install.sh->>Docker: 컨테이너 상태 확인 (ELK, Filebeat)
    alt 컨테이너 중 하나라도 비정상
        pre_install.sh->>Docker: docker-compose로 컨테이너 재시작
    else 모두 정상
        pre_install.sh->>EC2: "모든 컨테이너 정상" 메시지 출력
    end
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@lsh2613 lsh2613 requested a review from jeongmallro July 11, 2025 07:01
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
scripts/pre_install.sh (2)

8-13: 컨테이너 이름 변수 미인용 및 반복 코드 개선 제안

  1. 변수 확장은 따옴표로 감싸는 것이 안전합니다.
  2. 컨테이너 목록을 배열로 선언하면 가독성과 유지보수성이 높아집니다.
-NEED_RESTART=0
-for CONTAINER in pitchain_filebeat pitchain_logstash pitchain_kibana pitchain_elasticsearch; do
-  if ! docker ps --format '{{.Names}}' | grep -q "^${CONTAINER}$"; then
+NEED_RESTART=0
+CONTAINERS=(pitchain_filebeat pitchain_logstash pitchain_kibana pitchain_elasticsearch)
+for CONTAINER in "${CONTAINERS[@]}"; do
+  if ! docker ps --format '{{.Names}}' | grep -q "^${CONTAINER}$"; then
     echo "$CONTAINER 컨테이너가 실행 중이 아닙니다."
     NEED_RESTART=1
   fi
 done

15-18: 모든 컨테이너를 재빌드·재기동하는 것은 과도할 수 있습니다

다운된 컨테이너만 선택적으로 docker compose restart(또는 up -d) 하면 배포 시간이 단축되고 불필요한 이미지 빌드를 피할 수 있습니다.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 09dde94 and 49080c9.

📒 Files selected for processing (2)
  • appspec.yml (1 hunks)
  • scripts/pre_install.sh (1 hunks)
🧰 Additional context used
🪛 Shellcheck (0.10.0)
scripts/pre_install.sh

[warning] 5-5: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

(SC2164)

🔇 Additional comments (1)
appspec.yml (1)

15-18: BeforeInstall 훅 추가는 적절하지만, ApplicationStop 단계가 누락되었습니다

CodeDeploy 표준 순서는 ApplicationStop → BeforeInstall → AfterInstall → ApplicationStart 입니다.
stop.shAfterInstall에 남아 있으면 새 버전 코드 복사 후에 기존 컨테이너를 중지하게 되어 다운타임이 길어질 수 있습니다. ApplicationStop 으로 이동하는 방안을 검토해주세요.

@lsh2613 lsh2613 merged commit 8093eb4 into dev Jul 11, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant